from PIL import Image
from torch.utils.tensorboard import SummaryWriter
from torchvision import transforms


img_path = "../data/edata/train/bees/29494643_e3410f0d37.jpg"

write = SummaryWriter("../logs")
img = Image.open(img_path)
tool_toTensor = transforms.ToTensor()
tensor_img = tool_toTensor(img)

write.add_image("toTensor" , tensor_img)


# Normalize  mean 均值   std：标准差
# output[channel] = (input[channel] - mean[channel]) / std[channel]
print(tensor_img[0][0][1])
tool_nor = transforms.Normalize([0.5 , 0.5 , 0.5] , [0.5,0.5,0.5])
img_norm = tool_nor(tensor_img)
print(img_norm[0][0][1])
write.add_image("normalize",img_norm)


# resize
print(img.size)
tool_resize = transforms.Resize((1024*3,512))
# PIL---->resize--->PIL
img_resize = tool_resize(img)
# PIL---->toTensor---->tensor
img_resize = tool_toTensor(img_resize)
write.add_image("resize",img_resize)
print(img_resize.size)

# compose_resize
tool_resize_2 = transforms.Resize(512)
tool_compose = transforms.Compose([tool_resize_2,tool_toTensor])
# PIL----tool_compose--PIL--tensor
img_resize_2 = tool_compose(img)
write.add_image("resize_2",img_resize_2)


# hi ding xu lie (256, 200)  256 * 200
tool_random = transforms.RandomCrop(256)
tool_compose2 = transforms.Compose([tool_random,tool_toTensor])
for i in range(20):
    img_crop = tool_compose2(img)
    write.add_image("random_crop",img_crop,i)

write.close()



